public class ReConstruct {
    /**
     * 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
     *
     * 
     * @param preOrder int整型一维数组 
     * @param vinOrder int整型一维数组 
     * @return TreeNode类
     */
    public TreeNode reConstructBinaryTree (int[] preOrder, int[] vinOrder) {
        if (preOrder.length == 0 || vinOrder.length == 0 || preOrder.length != vinOrder.length) {
            return null;
        }
        int root_val = preOrder[0];
        TreeNode root = new TreeNode(root_val);
        int left_size = 0;
        for (int i = 0; i < vinOrder.length; i++) {
            if (vinOrder[i] == root_val) {
                left_size = i;
                break;
            }
        }
        int right_size = vinOrder.length - left_size - 1;

        int[] vinOrderLeft = new int[left_size];
        int[] vinOrderRight = new int[right_size];
        for (int i = 0; i < vinOrder.length; i++) {
            if (i < left_size) {
                vinOrderLeft[i] = vinOrder[i];
            } else if (i > left_size) {
                vinOrderRight[i - left_size - 1] = vinOrder[i];
            }
        }

        int[] preOrderLeft = new int[left_size];
        int[] preOrderRight = new int[right_size];
        for (int i = 1; i < preOrder.length; i++) {
            if (i <= left_size) {
                preOrderLeft[i - 1] = preOrder[i];
            } else {
                preOrderRight[i - left_size - 1] = preOrder[i];
            }
        }

        root.left = reConstructBinaryTree(preOrderLeft, vinOrderLeft);
        root.right = reConstructBinaryTree(preOrderRight, vinOrderRight);
        return root;
    }
}